package com.example.paopao.consumer.memer.controller;

import com.example.paopao.common.pojo.security.CurrenPrincipal;
import com.example.paopao.common.web.JsonResult;
import com.example.paopao.consumer.memer.pojo.entity.WorkerSubssinePhoneVO;
import com.example.paopao.consumer.memer.service.WorkerIntegralService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/v1/workers/")
@Api(tags = "联系个人名片积分扣除")
public class WorkerIntegralController {

    @Autowired
    private WorkerIntegralService integralService;

    @GetMapping("{id}/bussine")
    @ApiOperation("根据个人名片id 查询电话号码")
    @PreAuthorize("hasAuthority('/memer/release/person')")
    public JsonResult getPersonPhone(@PathVariable Long id,
                                     @AuthenticationPrincipal CurrenPrincipal currenPrincipal){
        WorkerSubssinePhoneVO phone = integralService.getPhone(id);
        if (phone!=null) {
            integralService.deductIntegral(currenPrincipal.getUserId());
        }
        return JsonResult.ok(phone);
    }
}
